#pragma once

#include<iostream>
#include<assert.h>
using namespace std;

namespace cx
{
	class string 
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;

		iterator begin();
		iterator end();
		const_iterator begin() const;
		const_iterator end() const;

		size_t size() const;
		size_t capacity() const;


		string(const char* str = "");
		string(const string& s);
		string(size_t n, char c);

		const char* c_str() const
		{
			return _str;
		}

		char& operator[](size_t pos);
		const char& operator[](size_t pos) const;
		string& operator=(const string& s);
		~string();


		void reserve(size_t n);
		void push_back(char c);
		void append(const char* s);


		string& operator+=(char c);
		string& operator+=(const char* s);

		void insert(size_t pos, char c);
		void insert(size_t pos, const char* s);
		void erase(size_t pos = 0, size_t len = npos);

		size_t find(char ch, size_t pos = 0);
		size_t find(const char* str, size_t pos = 0);

		void swap(string& s);
		string substr(size_t pos = 0, size_t len = npos);

		bool operator<(const string& s) const;
		bool operator>(const string& s) const;
		bool operator<=(const string& s) const;
		bool operator>=(const string& s) const;
		bool operator==(const string& s) const;
		bool operator!=(const string& s) const;
		void clear();


	private:
		char* _str;
		size_t _size;
		size_t _capacity;
		static const size_t npos;
	};

	istream& operator>>(istream& in, string& s);
	ostream& operator<<(ostream& out, string& s);
}
